package com.shanzmoo.admin.manager.store;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shanzmoo.db.store.entity.query.StorePurchaseSupplierQuery;
import com.shanzmoo.db.store.entity.vo.CheckSupplierVO;
import com.shanzmoo.db.store.entity.vo.StorePurchaseSupplierVO;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.db.store.service.IStorePurchaseSupplierService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 仓库采购供应商 管理器
 *
 * @author xueqz 2021-03-03
 */
@Slf4j
@Component
public class StorePurchaseSupplierManager {

    @Autowired
    private IStorePurchaseSupplierService storePurchaseSupplierService;

    /**
     * 分页查询
     */
    public PageRespBase<StorePurchaseSupplierVO> queryPage(StorePurchaseSupplierQuery query) {
        Page page = PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<StorePurchaseSupplierVO> reList = storePurchaseSupplierService.queryPageList(query);

        PageRespBase<StorePurchaseSupplierVO> result = PageRespBase.create(page, reList);
        return result;
    }

    /**
     * 选择采购供应商
     * @param query
     * @return
     */
    public List<CheckSupplierVO> queryAllList(StorePurchaseSupplierQuery query) {
        List<StorePurchaseSupplierVO> list = storePurchaseSupplierService.queryPageList(query);
        List<CheckSupplierVO> reList = list.stream().map(StorePurchaseSupplierVO::change).collect(Collectors.toList());
        return reList;
    }
}
